/**
 * 
 */
package fr.pud.server;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;

import fr.pud.client.model.Fleet;
import fr.pud.client.model.Queries;
import fr.pud.client.model.Route;
import fr.pud.utils.Properties;

/**
 * Apr 3, 2012 - OSE Ecole des Mines de Nantes
 * @author Pierre Reliquet
 */
public class Server implements IServer {
    private static final long serialVersionUID = -2638563268211653792L;
    private static IServer    instance         = null;

    public static IServer getInstance() throws RemoteException {
        if (instance == null) {
            instance = new Server();
        }
        return instance;
    }

    public static void main(String[] args) {
        try {
            System.out.println("Preparing Registry ...");
            Registry registry = LocateRegistry.createRegistry(IServer.PORT);
            System.out.println("Registry OK!");
            System.out.println("Preparing Server ...");
            UnicastRemoteObject.exportObject(getInstance(), PORT);
            registry.rebind(IServer.NAME, getInstance());
            System.out.println("Server OK!");
        }
        catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    private Server() throws RemoteException {
        super();
    }

    /*
     * (non-Javadoc)
     * @see fr.pud.server.IServer#solve(fr.pud.client.model.Fleet,
     * fr.pud.client.model.Queries)
     */
    @Override
    public ArrayList<Route> solve(Fleet aFleet, Queries aQueries,
            Properties theProperties) {
        return Solver.solve(aFleet, aQueries, theProperties);
    }
}
